package com.example.index.service.impl;

import com.example.index.entity.SchoolCooperationPictures;
import com.example.index.dao.SchoolCooperationPicturesDao;
import com.example.index.service.SchoolCooperationPicturesService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 校企合作 产教融合(SchoolCooperationPictures)表服务实现类
 *
 * @author makejava
 * @since 2023-08-29 15:32:22
 */
@Service("schoolCooperationPicturesService")
public class SchoolCooperationPicturesServiceImpl implements SchoolCooperationPicturesService {
    @Resource
    private SchoolCooperationPicturesDao schoolCooperationPicturesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SchoolCooperationPictures queryById(Integer id) {
        return this.schoolCooperationPicturesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param schoolCooperationPictures 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SchoolCooperationPictures> queryByPage(SchoolCooperationPictures schoolCooperationPictures, PageRequest pageRequest) {
        long total = this.schoolCooperationPicturesDao.count(schoolCooperationPictures);
        return new PageImpl<>(this.schoolCooperationPicturesDao.queryAllByLimit(schoolCooperationPictures, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param schoolCooperationPictures 实例对象
     * @return 实例对象
     */
    @Override
    public SchoolCooperationPictures insert(SchoolCooperationPictures schoolCooperationPictures) {
        this.schoolCooperationPicturesDao.insert(schoolCooperationPictures);
        return schoolCooperationPictures;
    }

    /**
     * 修改数据
     *
     * @param schoolCooperationPictures 实例对象
     * @return 实例对象
     */
    @Override
    public SchoolCooperationPictures update(SchoolCooperationPictures schoolCooperationPictures) {
        this.schoolCooperationPicturesDao.update(schoolCooperationPictures);
        return this.queryById(schoolCooperationPictures.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.schoolCooperationPicturesDao.deleteById(id) > 0;
    }
}
